package DBLayer;

import static org.junit.Assert.*;

import org.junit.Test;
import ModelLayer.Customer;


import java.util.ArrayList;

public class DBCustomerTest {

	@Test
	public void testInsert() throws Exception {
		Customer cus = new Customer();

		cus.setIdCustomer("nextIdCustomer");
		cus.setName("Jack");
		cus.setAddress("vejen 5");
		cus.setCity("Byen 2");
		cus.setPhoneNo("4025588125");
		cus.setEmail("anders@andersen.org");
		cus.setCvrNo("2508291232429");
		cus.setAccountNo("0005461235465");

		DBCustomer dbCus = new DBCustomer();
		int i = dbCus.insertCustomer(cus);

		if(i == 1)
		{
			System.out.println("Works");
		}
		else
			fail();
	}

    @Test
	public void testUpdate() throws Exception {
		Customer cus = new Customer();
		DBCustomer dbCus = new DBCustomer();
		cus = dbCus.findCustomerById("8889");

		cus.setName("Dr Dre");

		int i = dbCus.updateCustomer(cus);
	}

    @Test
	public void testDelete() throws Exception
	{
		Customer cus = new Customer();
		DBCustomer dbEmp = new DBCustomer();
		cus = dbEmp.findCustomerById("8889");

		if(cus != null)
		{
			int i = dbEmp.deleteCustomer("8889");
		}
		else
			fail();
	}

    @Test
	public void testGetAllCustomer() throws Exception
	{
		ArrayList<Customer> cusList= new ArrayList<Customer>();
		DBCustomer dbCus = new DBCustomer();
		cusList = dbCus.getAllCustomers();

		if(cusList != null)
			for(Customer cus : cusList)
				System.out.println("idCustomer : " + cus.getIdCustomer() + " Name : " + cus.getName());
		else
			fail();

	}

    @Test
	public void testFindCustomerByName()
	{
		Customer cus = new Customer();
		DBCustomer dbCus = new DBCustomer();
		cus = dbCus.findCustomerByName("Bjarke Poulsen");

        if (cus != null){
            System.out.println("CustomerName has been found");
            System.out.println("Name : " + cus.getName() + ", idCustomer : " + cus.getIdCustomer());
        }
        else fail();
	}

    @Test
    public void testFindCustomerById() throws Exception {
        DBCustomer dbCus = new DBCustomer();
        Customer cus = dbCus.findCustomerById("8888");

        if (cus != null){
            System.out.println("CustomerId has been found");
            System.out.println("idCustomer : " + cus.getIdCustomer() + ", Name : " + cus.getName());
        }
        else fail();
    }
}
